<template>
	<view>
		<view class="example">
			<view class="rate">
				<uni-rate allow-half :value="formData.rate" margin="20"/>
			</view>
			<view>
				<textarea v-model="formData.introduction" placeholder="请输入你的评价" placeholder-style="font-size: 38rpx;color:grey"></textarea>
			</view>
			<view class="btn">
				<button type="primary" class="btn1" @click="addcomment">发布</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				formData:{
					introduction:"",
					rate:3.5,
					id:0,
				},
				orderId:0,
			}
		},
		onLoad(option){
			console.log(option);
			this.orderId=option.id;
		},
		onShow() {
			uni.getStorage({
				key:"userId",
				success:res=>{
					this.formData.id=res.data;
				}
			})
		},
		methods: {
			addcomment(){
				console.log(this.formData.id);
				uni.request({
					url:"http://localhost:8080/goodsComment/add",
					method:"POST",
					data:{
						// 用户id
						userId:this.formData.id,
						// 订单id
						orderId:this.orderId,
						// 内容
						comment:this.formData.introduction,
						score:this.formData.rate,
					},
					success: (res) => {
						if(res.data.code==200){
							uni.showToast({
								title:"发布成功",
								icon:"none",
							})
						};
						uni.navigateTo({
							url:"/my/order/index",
							// 成功跳转失败跳转错误信息
								success(res) {
								//console.log('成功啦',res);
								},
								fail(err) {
								//console.log('失败啦',err);
								}
						});
					}
				})
			}
		}
	}
</script>

<style>
	page {
		background-color: #111224;
	}
	textarea{
		color: white;
		font-size: 38rpx;
	}
	.btn{
		margin-top: 50rpx;
	}
	.btn1{
		background-color:#3399ff;
	}
	.rate{
		display: flex;
	}
</style>
